package com.yuchen.ishop.service.admin.seller.impl;

import com.yuchen.core.MyPager;
import com.yuchen.core.jdbc.BaseDao;
import com.yuchen.ishop.entity.Seller;
import com.yuchen.ishop.service.admin.seller.SellerService;
import org.apache.commons.lang.StringUtils;
import org.nutz.dao.Cnd;
import org.nutz.dao.sql.Criteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;


/**
 *
 */
@Service
@Transactional
public class SellerServiceImpl implements SellerService {

    @Autowired
    private BaseDao dao;

    @Override
    public MyPager find(Map params, MyPager pager) {
        Criteria cri = Cnd.cri();
        if(StringUtils.isNotBlank((String) params.get("name"))){
            cri.where().andLike("name",params.get("name")+"%");
        }
        if(StringUtils.isNotBlank((String) params.get("state"))){
            cri.where().andEquals("state",params.get("state"));
        }
        if(StringUtils.isNotBlank((String) params.get("identification"))){
            cri.where().andEquals("identification",params.get("identification"));
        }
        cri.getOrderBy().desc("createTime");
        return dao.queryPager(Seller.class,cri,pager);
    }

    @Override
    public Seller insert(Seller seller) {
        return dao.insert(seller);
    }

    @Override
    public int update(Seller seller,boolean isIgnoreNull) {
        if(isIgnoreNull) return dao.updateIgnoreNull(seller);
        return dao.updateIgnoreNull(seller);
    }

    @Override
    public Seller getById(Long id) {
        return dao.fetch(Seller.class,id);
    }


    @Override
    public int delete(Long id) {
        return dao.delete(Seller.class,id);
    }
}
